<?php
/**
 * @Author:      lyt
 * @DateTime:    2016-12-22 11:25:53
 * @Description: 用于每天检测 流水表的
 */

$api_service_path = __DIR__ . "/../../../api/";
ob_start();
require_once($api_service_path . "public/index.php");
ob_end_clean();

DB::connection()->disableQueryLog(); 
$mail = array(
    'ahlyt@anhuibj.com',
    'ahjdx@anhuibj.com',
);

$date=time()-86400;
// $date=strtotime('2016-12-25');
$mdb=MaintenanceShops::where('status',1)->get();
$finally=array();
foreach ($mdb as $_mdb) {//计算每个点的营业额

	$begin_date=date('Y-m-d 00:00:00',$date);
	$end_date=date('Y-m-d 23:59:59',$date);
	$response = Report::get_supply_stock_new($begin_date,$end_date,1,$_mdb->id);
	foreach ($response as $_r) {//验证每个耗材是否正常
		$temp_count=round($_r['start_stock']+$_r['into_stock']+$_r['return_into_stock']-$_r['orderout_stock']-$_r['saleout_stock']-$_r['diaochu_stock']+$_r['pandian_stock']-$_r['supplier_stock']-$_r['end_stock'],2);
		if($temp_count!=0){
			$_r['shop_name']=$_mdb->name;
			$finally[]=$_r;
		}
	}
	Log::info("门店".$_mdb->id." 日期 ".date('Y-m-d',$date).'完毕');
	echo "门店".$_mdb->id." 日期 ".date('Y-m-d',$date).'完毕';
}
$data_arr = array(
    'mail' => $mail,
    'report' => $finally
);
if(sizeof($finally)>0){
	Mail::send('emails.stork', $data_arr, function($message)use ($data_arr)
	{
	    $message->to($data_arr['mail'], '进销存异常耗材')->subject('进销存异常耗材');
	});
}

